﻿<%@ Page Title="Part Master" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
   CodeBehind="PartMaster.aspx.cs" Inherits="Billder.PartMaster" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">

<table width="100%">
    <tr>
        <td>
            <label for="txtPartNumber" >Numero de parte:</label><br/>
            <asp:TextBox runat="server" ID="txtPartNumber" CssClass="textEntry" billdervalidation="notEmpty" onblur="checkUnique('txtPartNumber');"></asp:TextBox>
            <br/>
            <label for="txtManufacturerPartNumber">NP del manufacturero:</label><br/>
            <asp:TextBox runat="server" ID="txtManufacturerPartNumber" billdervalidation="notEmpty" CssClass="textEntry" onblur="checkUnique('txtManufacturerPartNumber');"></asp:TextBox><br/>
            <label for="txtDescription">Descripcion:</label><br/>
            <asp:TextBox runat="server" ID="txtDescription"  billdervalidation="notEmpty" CssClass="textEntry"></asp:TextBox><br/>
            <label for="txtManufacturer">Manufacturero:</label><br/>
            <asp:TextBox runat="server" ID="txtManufacturer" billdervalidation="notEmpty" CssClass="textEntry"></asp:TextBox><asp:HiddenField runat="server" ID="txtFKManufacturer"></asp:HiddenField><br/>
            <label for="txtDistributor">Distribuidor:</label><br/>
            <asp:TextBox runat="server" ID="txtDistributor" billdervalidation="notEmpty" CssClass="textEntry"></asp:TextBox><asp:HiddenField runat="server" ID="txtFKDistributor"></asp:HiddenField> <br/>   
            <label for="txtQuote">Cotizacion:</label><br/>
            <asp:FileUpload runat="server" ID="txtQuote" CssClass="textEntry" /><br/>
        </td>
        <td>
            <label for="txtPurchacePrice">Precio de compra:</label><br/>
            <asp:TextBox runat="server" ID="txtPurchacePrice" billdervalidation="float"  CssClass="textEntry"></asp:TextBox><br/>
            <label for="txtPurchaseQty">Cantidad de compra:</label><br/>
            <asp:TextBox runat="server" ID="txtPurchaseQty" billdervalidation="float"  CssClass="textEntry"></asp:TextBox><br/>
            <label for="txtDatasheet">Hoja tecnica:</label><br/>
            <asp:FileUpload runat="server" ID="txtDatasheet" CssClass="textEntry"/><br/>
            <label for="txtAdders">Adders:</label><br/>
            <asp:TextBox runat="server" ID="txtAdders"  billdervalidation="float" CssClass="textEntry"></asp:TextBox><br/>
            <label for="txtSalesPrice">Precio de venta:</label><br/>
            <asp:TextBox runat="server" ID="txtSalesPrice"  billdervalidation="float" CssClass="textEntry disabled" Enabled="false"></asp:TextBox><br/>
            <label for="txtSalesMultiple">Multiplo de venta:</label><br/>
            <asp:TextBox runat="server" ID="txtSalesMultiple"  billdervalidation="float" CssClass="textEntry disabled" Enabled="false"></asp:TextBox><br/>
        </td>
        <td><img alt="Part photo" runat="server" id="partImg" src="Image.aspx?PK=0&img=none" height="250" ondblclick="activateImg();"/><br /><input type="file" name="partImageFile" id="partImageFile" onchange="fnUploadImg();" /></td>
        <td>
        <asp:Button ID="btnSave" Text="Guardar" runat="server" CssClass="submitButton" />
        <asp:Button ID="btnApprove" Text="Aprobar" runat="server" CssClass="submitButton" 
                Enabled="false" onclick="btnApprove_Click" OnClientClick="return confirmApprove(); " /><asp:Button ID="btnReject" Text="Rechazar" runat="server" CssClass="submitButton" 
                Enabled="false" onclick="btnReject_Click" OnClientClick="prepareReject();" />
        </td>
    </tr>
</table>
<div id="divList" runat="server" style="width:100%; height:45em;"></div>
<div id="divAffectedBOMs" runat="server" style="width:100%; height:45em;">
<div id="divAffectedBOMsChild" runat="server">&nbsp;</div>
<asp:Button ID="btnApproveOk" Text="Continuar" runat="server" CssClass="submitButton" 
               onclick="btnApprove_Click"  /></div>
<iframe id="imgIfr" src="" width="0" height="0" style="border:none;"></iframe>
<asp:HiddenField ID="txtImgCode" runat="server"></asp:HiddenField><asp:HiddenField ID="txtPKPartMaster" runat="server"></asp:HiddenField><asp:HiddenField ID="txtPNID" runat="server" Value="0"></asp:HiddenField>
<asp:HiddenField ID="txtAction" runat="server" Value="none"></asp:HiddenField><asp:HiddenField ID="txtStatus" runat="server" Value="none"></asp:HiddenField>
<!--script src="BillderWS.asmx/js" type="text/javascript"></script-->
<script type="text/javascript" src="Scripts/Common.js"></script>
   <script type="text/javascript" >
       checkUnique = function (ctl) {
           return true;
       }
       $("#MainContent_divAffectedBOMs").dialog({ autoOpen: false, modal: true });
       prepareReject = function (pk) {
           
           document.getElementById("MainContent_txtAction").value = "prepareReject";
       }
       prepareEdit = function (pk) {
           document.getElementById("MainContent_txtPNID").value = pk;
           document.getElementById("MainContent_txtAction").value = "prepareEdit";
           document.getElementById("MainContent_txtAction").form.submit();
       }

   
 

       ManufResult = function (event, item) {
           fnHdlJQResult("MainContent_txtFKManufacturer", item);
       }
       ManufSearch = function (event, ui) {
           fnHdlJQSearch("MainContent_txtFKManufacturer");
       }
       ManufParse = function (data) {
           fnHdlJQParse("MainContent_txtFKManufacturer", data);
       }
       DistResult = function (event, item) {
           fnHdlJQResult("MainContent_txtFKDistributor", item);
       }
       DistSearch = function (event, ui) {
           fnHdlJQSearch("MainContent_txtFKDistributor");
       }
       DistParse = function (data) {
           fnHdlJQParse("MainContent_txtFKDistributor",data);
       }
       $("#MainContent_txtManufacturer").autocomplete("Manufacturer.aspx", { parse: ManufParse ,autoFill:true }).result(ManufResult).search(ManufSearch);
       $("#MainContent_txtDistributor").autocomplete("Distributor.aspx", { parse: DistParse, autoFill: true }).result(DistResult).search(DistSearch);
       confirmApprove = function () {//"TOR-001"
           var result = jQuery.ajax({ url: "BillderWS.asmx/getPartBOMs", data: {part:document.getElementById("MainContent_txtPartNumber").value }, success: confirmApproveSuccess,type:"POST" });
           return false;
       }
       function loadIndex(xml) { // load indexfile
           // most current browsers support document.implementation
           if (document.implementation && document.implementation.createDocument) {
               xmlDoc = document.implementation.createDocument("", "", null);
               xmlDoc.loadXML(xml);
               return xmlDoc;
           }
           // MSIE uses ActiveX
           else if (window.ActiveXObject) {
               xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
               xmlDoc.async = "false";
               xmlDoc.loadXML(xml);
               return xmlDoc;
           }
       }
       confirmApproveSuccess = function (result) {
           //var doc = loadIndex(result);
           var resultArr = new Array();
           var strings = result.getElementsByTagName("string");
           for (var i = 0; i < strings.length; i++) {
               resultArr.push(strings[i].childNodes[0].data);
           }
           if (resultArr.length == 0) {
               return true;
           }
           else {
               var sb = new Array();
               sb.push("Se afectaran los siguientes BOMs:\n");
               for (var i = 0; i < resultArr.length; i++) {
                   sb.push(resultArr[0] + "\n");
               }

               $("#MainContent_divAffectedBOMsChild").html(sb.join("<br/>") + "<br/>");
               $("#MainContent_divAffectedBOMs").dialog("open");
               sb.push("\nEsta de acuerdo?\n"); ;
               var response = confirm(sb.join(""));


               if (!response) {
                   $("#MainContent_divAffectedBOMs").dialog("close");
                   return false;
               } else {
                   $("#MainContent_btnApprove").attr("onclick", "");
                   // document.getElementById("btnContinue").setAttribute("onclick", "actualApprove();");
               }
           }
       }
       actualApprove = function () {
           
           $("#MainContent_btnApprove").click();
       }
       hideDialog = function () {
           $("#MainContent_divAffectedBOMs").dialog("close");
       }
        </script>
       
</asp:Content>
